The present invention generally relates to data processing. The invention relates more specifically to selectively forcing network communications, such as HTML results generated by a Web server, to go a particular location.
In a client/server computing environment a need may arise to enable a client to communicate with two servers, each of which provide functions that represent a portion of a service desired by the client. In some cases, it is desirable to permit the client to communicate with only a first one of the two servers and to prevent direct contact between the client and the other of the two servers.
FIG. 1 is a block diagram of a networked computer system in which the foregoing general problem may arise. Client 102 is a computer device such as a workstation, server, router, or switch. Client 102 is coupled to network 104, which is an interconnected combination of computers, terminals, or peripherals used to provide communications a between two or more points. A first server 106 and a second server 108 are coupled to network 104, logically separated from client 102. In one embodiment, client 102, network 104, and servers 106, 108 communicate using TCP/IP network protocols, and using HTTP protocol messages that comprise requests and responses. Such protocols are exemplary and not required.
Client 102 may communicate an HTTP request for a service to network 104. The request includes a name or other identifier of server 106, which client 102 expects to provide the requested service. Network 104 locates server 106 and routes the request to server 106, thereby establishing a logical connection 110 from client 102 to the server. Server 106 determines that it cannot provide the function or service solicited in the request, but that server 108 can provide the function or service. Accordingly, software elements in server 106 automatically divert or xe2x80x9credirectxe2x80x9d the request to server 108 over a logical connection 112, which may physically travel through the network 104. Server 108 processes the request, generates a response message, and sends the response message back to client 102 over logical connection 114, which may pass through network 104.
In this scenario, when the client and the servers use HTTP, the response message may include a document formatted using a structured markup language, such as HTML. The HTML document may contain hyperlinks or other references to resources within server 108, or other servers or network elements. As a result, client 102 may select one of the hyperlinks or references, and thereby attempt to request a service of server 108 directly along connection 114. Server 106 would not be involved in processing such a request.
This result is undesirable in several circumstances. The server 106 may have been designated as authoritative for certain kinds of transactions. The server 106 may have redirected the original request to server 108 solely because server 106 cannot directly process the request, whereas server 108 can, but server 106 may need to remain in control of the overall transaction. For example, server 106 may have redirected the original request to server 108 just to carry out a specialized or subordinate task, although server 106 remains responsible for the total transaction or for presenting a consistent interface to the client 102.
Accordingly, there is a need in this field for a mechanism that allows a client request to be redirected from a first server to a second server, while keeping the first server in control of subsequent requests by the client for services of the second server.
In particular, there is a need for a mechanism that prevents the client from directly communicating with the second server even after the first server has redirected a request of the client to the second server.
There is a specific need in Internet protocol networks, such as Intranets or the Internet in which clients and servers use TCP/IP and HTTP, to force subsequent requests resulting from HTML generated by the second server to come back to the first server for further redirection.
The foregoing needs and objects, and other needs and objects that will become apparent from the following description, are achieved by the present invention, which comprises, in one aspect, a method of redirecting a request from a client that may be served by a first server to a second server. Generally, the method involves the computer-implemented steps of receiving a client request at the second server; automatically forwarding the client request to the first server; receiving a result message from the first server; identifying, in the result message, references to resources of the first server; replacing the references to resources of the first server with translated references that reference the second server; and sending the translated references to the client as a response to the client request.
One feature of this embodiment further involves receiving, at the second server, a second client request based on the response; and for the second client request, repeating the steps of automatically forwarding, receiving a result message, identifying, replacing, and sending. According to another feature, the identifying step involves parsing the result message to identify one or more tags that are associated with references to resources of the first server; and matching the tags to attributes that identify resources of the first server.
According to another feature, the replacing step involves attaching, to each of the references to resources of the first server, a value that identifies a process of the second server that carries out the identifying step and the replacing step. A related feature is that the replacing step comprises attaching, to each of the references to resources of the first server, a value that identifies a process of the second server that carries out the identifying step and the replacing step.
In yet another feature, the step of receiving a client request at the second server involves receiving a client HTTP request at a second Web server; the step of automatically forwarding the client request to the first server is redirecting the client HTTP request to a first Web server; and the step of receiving a result message from the first server involves receiving an HTTP response message from the first Web server that contains an HTML document. A related feature is that the step of identifying, in the result message, references to resources of the first server comprises parsing the HTML document to identify one or more URLs. Another related feature is that the step of identifying, in the result message, references to resources of the first server comprises parsing the HTML document to identify one or more relative URLs that lack an explicit reference to the first server or one or more URLs that explicitly reference the first server. Yet another related feature is that the steps of identifying and replacing are carried out using a CGI script that may contain one or more associated software elements, and the step of replacing involves attaching, to each of the references to resources of the first server, a value that identifies the CGI script.
According to another feature, the steps of identifying, replacing and sending involve stream tokenizing the result message into a plurality of tags, each of the tags having zero or more attributes; storing in an output message any tags that are not associated with references to resources of the first server; for each tag that is associated with a reference to a resource of the first server: identifying a resource attribute associated with the tag that identifies the resource; prepending a value, which identifies a software element that carries out the steps of identifying and replacing, to the resource attribute; and storing the tag, value, and resource attribute in the output message.
In one embodiment, a function resides at a first Web server. The function redirects all requests to it from clients to a second Web server. The first Web server receives the result of the request from the second Web server. If the result contains an HTML document, then the first server changes all Uniform Resource Locators (xe2x80x9cURLxe2x80x9ds) in the HTML document that reference the second server to reference the function of the first server instead. The modified HTML document is then passed back to the client. As a result, subsequent requests based on the HTML document are forced to come to the first server. Advantageously, functions offered by two Web servers may be combined while causing the client to view the functions as being provided only by the first Web server.